linked_list Derived Type

type, public :: linked_list

Defines a generic, linked-list container.


Finalization Procedures

final :: ll_destroy

  • private subroutine ll_destroy(this)

    Finalizer for the linked_list type responsible for clean-up duties when the list goes out of scope.

    Arguments

    Type IntentOptional Attributes Name
    type(linked_list), intent(inout) :: this

    The linked_list object.


Type-Bound Procedures

procedure, public :: clear => ll_clear

  • private subroutine ll_clear(this)

    Clears the entire list.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

procedure, public :: count => ll_count

  • private pure function ll_count(this) result(rst)

    Gets the number of items in the list.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(in) :: this

    The linked_list object.

    Return Value integer(kind=int32)

procedure, public :: get => ll_get

  • private function ll_get(this) result(rst)

    Gets the current item.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(in) :: this

    The linked_list object.

    Return Value class(*), pointer

    The currently referenced item from the list. This may be null if the list is empty.

procedure, public :: move_to_first => ll_move_to_first

  • private subroutine ll_move_to_first(this)

    Moves the current position in the list to the first item.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

procedure, public :: move_to_last => ll_move_to_last

  • private subroutine ll_move_to_last(this)

    Moves the current position in the list to the last item.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

procedure, public :: next => ll_move_to_next

  • private function ll_move_to_next(this) result(rst)

    Moves to the next item in the list.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

    Return Value logical

    Returns true if the move was successful; else, returns false. Typically a false value indicates the end of the list; however, a false value can be encountered if the list is emtpy.

procedure, public :: pop => ll_pop

  • private subroutine ll_pop(this)

    Pops an item off the back of the list.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

procedure, public :: previous => ll_move_to_previous

  • private function ll_move_to_previous(this) result(rst)

    Moves to the previous item in the list.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

    Return Value logical

    Returns true if the move was successful; else, returns false. Typically a false value indicates the end of the list; however, a false value can be encountered if the list is emtpy.

procedure, public :: push => ll_push

  • private subroutine ll_push(this, x, manage)

    Pushes an item onto the end of the list.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

    class(*), intent(in), target :: x

    The object to store.

    logical, intent(in), optional :: manage

    An optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.

procedure, public :: set => ll_set

  • private subroutine ll_set(this, x, manage)

    Replaces the current item in the list with the supplied item.

    Arguments

    Type IntentOptional Attributes Name
    class(linked_list), intent(inout) :: this

    The linked_list object.

    class(*), intent(in), target :: x

    The object to store.

    logical, intent(in), optional :: manage

    An optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.